package org.zsk.cs.algorithnm.loadbalance.sendorder.impl;

import org.zsk.cs.algorithnm.entity.EmployTask;
import org.zsk.cs.algorithnm.loadbalance.sendorder.LoadBalance;
import org.zsk.cs.algorithnm.loadbalance.sendorder.SendOrderUtil;

import java.util.List;
import java.util.Random;

/**
 * 负载均衡-随机派单
 * @author zsk
 * 2021/4/19 下午8:05
 */
public class RandomLoadBalancer implements LoadBalance<EmployTask> {
    private static Random random=new Random();

    @Override
    public EmployTask pickOne() {
        List<EmployTask> availableEmployTasksInList = SendOrderUtil.getAvailableEmployTasksInList();
        return availableEmployTasksInList.get(random.nextInt(availableEmployTasksInList.size()));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            System.out.println(new RandomLoadBalancer().pickOne().toString());
        }
    }
}
